﻿/**
 * @author sminutoli
 * version 1.1
 * El seteo de privado o publico está bastante cabezón al igual que el "detector" de si da o no da para mensaje de texto
 */
 
import com.dinmax.flash.central.bridge.CENTRALBridge
import com.dinmax.flash.draw.cabeza.ControlCabeza
import com.dinmax.flash.draw.cabeza.ButtonCabeza

class com.dinmax.flash.central.bridge.CONTACTItemBridge 
extends ControlCabeza
implements com.dinmax.flash.draw.cabeza.SelectedListener {
	
	private static var FRAME_PUBLIC:Number = 1;
	private static var FRAME_PRIVATE:Number = 2;
	private static var FRAME_USER:Number = 3;
	
	private var txt_label:TextField;
	private var sLabel:String;
	private var mail:String;
	private var visibility:String;
	private var extID:Number;
	private var phone:Number;
		
	private var mcSendMail:ButtonCabeza;
	private var mcSendText:ButtonCabeza;
	private var mcMakeCall:ButtonCabeza;
	private var mcVisibility:ButtonCabeza;
	private var mcShortcut:ButtonCabeza;
	
	public function CONTACTItemBridge() {
		//trace("new CONTACTItemBridge()");
	};
	
	public function onLoad():Void {
		super.onLoad();
		this.txt_label.text = this.sLabel;
		this.mcSendMail.addListener(this);
		this.mcSendText.addListener(this);
		this.mcMakeCall.addListener(this);
		this.mcVisibility.addListener(this);
		this.mcShortcut.addListener(this);
		return;
	};
	
	public function initChild(control:ControlCabeza):Void {
		switch(control){
			case this.mcVisibility:
			this.setVisibility(this.visibility);
			this.checkID();
			break;
		};
		return;	
	};
	
	public function setVisibility(type:String):Void {
		if(type == "Private"){
			this.mcVisibility.gotoAndStop(CONTACTItemBridge.FRAME_PRIVATE);
		} else if(type == "User"){ 
			this.mcVisibility.gotoAndStop(CONTACTItemBridge.FRAME_USER);
		} else {
			this.mcVisibility.gotoAndStop(CONTACTItemBridge.FRAME_PUBLIC);
		};
		this.visibility = type;
		return;
	};
	
	public function getVisibility():String {
		return this.visibility;
	};
	
	public function setLabel(label:String):Void {
		this.sLabel = label;
		return;
	};
	
	public function setMail(mail:String):Void {
		this.mail = mail;
		return
	};
			
	public function selected(button:ControlCabeza):Void {
		switch(button){
			case this.mcSendMail:
			//trace("CONTACTItemBridge.as | debería mandar mail a "+this.mail);
			getURL("mailto:"+this.mail);
			break;
			
			case this.mcSendText:
			CENTRALBridge.getActive().writeMessage(this.getExtID());						
			break;
			
			case this.mcMakeCall:
			CENTRALBridge.getActive().outgoingCall(this.getPhone());
			break;
			
			case this.mcVisibility:
			this.selectEvent();					
			break;
			
			case this.mcShortcut:
			CENTRALBridge.getActive().addShortcut(this.sLabel, this.mail, this.phone);
			break;
		};
		
		return;
	};
		
	public function getPhone():Number {
		return phone;
	}

	public function setPhone(phone:Number):Void {
		this.phone = phone;
		return;
	}

	public function getExtID():Number {
		return extID;
	}

	public function setExtID(extID:Number):Void {
		this.extID = extID;
		this.checkID();
		return;
	}
	
	public function checkID():Void {
		if(String(this.getExtID()).length > 3){
			this.mcSendText.enabled = false;
			this.mcSendText._alpha = 70;
		} else {
			this.mcSendText.enabled = true;
			this.mcSendText._alpha = 100;
		};
		return;
	};

};